package com.wannengbang.cloudleader.homepage;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.google.gson.Gson;
import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.base.BaseActivity;
import com.wannengbang.cloudleader.base.DataCallBack;
import com.wannengbang.cloudleader.bean.ComplianceProgressBean;
import com.wannengbang.cloudleader.bean.ItemListDTO;
import com.wannengbang.cloudleader.homepage.adapter.ComplianceProgressAdapter;
import com.wannengbang.cloudleader.homepage.adapter.ProductClassifyListAdapter;
import com.wannengbang.cloudleader.homepage.adapter.TowComplianceProgressAdapter;
import com.wannengbang.cloudleader.homepage.model.HomePageModelImpl;
import com.wannengbang.cloudleader.widget.AppTitleBar;
import com.wannengbang.cloudleader.widget.WrapContentLinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class ComplianceProgressActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.tv_no)
    TextView tv_no;
    @BindView(R.id.rv_one)
    RecyclerView rv_one;
    @BindView(R.id.rv_tow)
    RecyclerView rv_tow;
    @BindView(R.id.tv_one_remark)
    TextView tv_one_remark;
    @BindView(R.id.tv_tow_remark)
    TextView tv_tow_remark;

    private HomePageModelImpl homePageModel;
//    private List<ComplianceProgressBean.Data.TaskOne.lists> list = new ArrayList<>();
//    private ComplianceProgressAdapter listAdapter;
    private TowComplianceProgressAdapter towlistAdapter;

    private List<ComplianceProgressBean.Data.TaskTwo.Lists> towlist = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_compliance_progress);
        ButterKnife.bind(this);
        homePageModel = new HomePageModelImpl();
        initView();
        initData();
    }

    private void initView() {
//        listAdapter = new ComplianceProgressAdapter(list);
//        //设置布局管理器
//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
//        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//        rv_one.setLayoutManager(linearLayoutManager);
//
//        rv_one.setAdapter(listAdapter);


        towlistAdapter = new TowComplianceProgressAdapter(towlist);
        //设置布局管理器
        LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(this);
        linearLayoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
        rv_tow.setLayoutManager(linearLayoutManager1);

        rv_tow.setAdapter(towlistAdapter);


    }

    private void initData() {
        homePageModel.requestDeviceTaskOne(new DataCallBack<ComplianceProgressBean>() {



            @Override
            public void onSuccessful(ComplianceProgressBean bean) {

//                try {
//                    ComplianceProgressBean.Data.TaskOne taskOne = bean.getData().get(0).getTaskOne();
//                    list.addAll(taskOne.getList());
//                    listAdapter.notifyDataSetChanged();
//
//                    tv_no.setText("SN："+bean.getData().get(0).getNo());
//                    tv_one_remark.setText(bean.getData().get(0).getTaskOne().getRemark());
//
//                }catch (Exception e){
//
//                }

                try {
                    tv_no.setText("SN："+bean.getData().get(0).getNo());
                    ComplianceProgressBean.Data.TaskTwo taskTwo = bean.getData().get(0).getTaskTwo();
                    towlist.addAll(taskTwo.getList());

                    towlistAdapter.notifyDataSetChanged();
                    tv_tow_remark.setText(bean.getData().get(0).getTaskTwo().getRemark());

                }catch (Exception e){

                }

            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }

}